import { FC, Suspense, lazy } from 'react'
import { Routes, Route } from 'react-router-dom'
import { getUserInfo } from 'src/hooks/root/selector';

import { useRecoilValue } from 'recoil';
import actions from 'src/entry/actions';
const FormGroupComponent = lazy(() => import('./group'))
const FormComponent = lazy(() => import('./form'))
const WorkbenchesComponent = lazy(() => import('./workbenches'))

const PageRouter: FC = () => {
  // 方法一：在localStroage中获取用户数据, getUserInfo中实现，此方法获取初始化数据
  const userInfo = useRecoilValue(getUserInfo)
  // 方法二：监听全局状态方法，获取最新数据，此方法获取实时数据
  actions.onGlobalStateChange((state: any) => {
    if (state.type === 'userInfo') {

    }
  })
  return (
    <Routes>
      <Route path='form/group' element={<Suspense>
        <FormGroupComponent />
      </Suspense>} />
      <Route path='form' element={<Suspense>
        <FormComponent />
      </Suspense>} />
      <Route path='workbenches' element={<Suspense>
        <WorkbenchesComponent />
      </Suspense>} />
    </Routes>)
}

export default PageRouter